package com.lgd.tools;

import clover.org.apache.commons.lang.math.RandomUtils;
import com.itextpdf.text.Document;
import com.itextpdf.text.Font;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfWriter;

import java.io.FileOutputStream;

public class ToPDF {

	// 创建Pdf文挡
	public static void formPdfDocument(String[] content) {
		Document document = new Document();
		try {
			//使用PDFWriter进行写文件操作
			PdfWriter.getInstance(document, new FileOutputStream(
					"D:\\FILE\\pdf\\"+content[RandomUtils.nextInt(content.length)]+".pdf"));
			document.open();
			// 中文字体
			BaseFont bfChinese = BaseFont.createFont("STSong-Light",
					"UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
			Font fontChinese = new Font(bfChinese, 12, Font.NORMAL);
            for (int i = 0; i < content.length; i++) {
                document.add(new Phrase(content[RandomUtils.nextInt(content.length)]+" ",fontChinese));

            }
		} catch (Exception e) {
			e.printStackTrace();
		}
		document.close();
	}

	public static void main(String[] args) throws Exception {
		formPdfDocument(WordBase.getWords(500));
	}

}
